<template>
	<view
		:style="'order:'+item.order+';'+item.css"
		class="list-hashtag">
		<template v-if="listStatus === 'success'">
			<view
				@click="$_to('hashtag/detail?hid=' + item.htid)"
				class="for"
				v-for="(item, index) in list">
				<view class="_sort">{{index+1}}.</view>
				<view class="_name">{{item.name}}</view>
				<view class="_post-count">{{item.postCount}}{{$t('newPosts')}}</view>
				<view class="_post-count">{{item.commentCount}}{{$t('contentCommentCountDesc')}}</view>
				<view class="_right">
					<view>
						<text class="iconfont icon-good"></text><text>{{item.likeCount}}</text>
					</view>
					<view>
						<text class="iconfont icon-favorite"></text><text>{{item.followCount}}</text>
					</view>
				</view>
			</view>
			<view
				class="more-content"
				v-if="item.page"
				@click="clickMoreButton">
				{{listPageText}}
			</view>
		</template>
		<template v-if="listStatus === 'loading'">
			<view class="_loading">
				<view class="skeleton-screen" v-for="itemData in item.query.pageSize?item.query.pageSize:1"></view>
			</view>
		</template>
		<template v-if="listStatus === 'empty'">
			<global-empty></global-empty>
		</template>
	</view>
</template>

<script>
	export default {
		name:"list-hashtag",
		props:{
			item:{
				type:Object,
				default:null
			}
		},
		data() {
			return {
				list:[],
				listStatus:"loading",
				listPage:2,
				listPageText: this.$t('clickToLoadMore')
			};
		},
		mounted(){
			this.getList();
		},
		methods: {
			getList(){
				this.$_request(
					"GET", "/api/fresns/v1/hashtag/list",
					{
						...this.item.query,
						"page":1,
						"filterType":"whitelist",
						"filterKeys":"htid,name,postCount,commentCount,likeCount,followCount,interaction.likeEnabled,interaction.followEnabled,interaction.likeStatus,interaction.followStatus"
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = res.data.data.list;
							this.listStatus = "success";
						} else {
							this.listStatus = "empty";
						}
					}
				)
			},
			clickMoreButton(){
				if (this.listPageText == this.$t('loading')) { return }
				this.listPageText = this.$t('loading');
				this.$_request(
					"GET", "/api/fresns/v1/hashtag/list",
					{
						...this.item.query,
						"page": this.listPage,
						"filterType":"whitelist",
						"filterKeys":"htid,name,postCount,commentCount,likeCount,followCount,interaction.likeEnabled,interaction.followEnabled,interaction.likeStatus,interaction.followStatus"
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = this.list.concat(res.data.data.list);
							this.listPage++
							this.listPageText = this.$t('clickToLoadMore')
						} else {
							this.listPageText = this.$t('listEmpty')
						}
					}
				)
			}
		},
	}
</script>

<style lang="scss" scoped>
.list-hashtag{
	padding: 0 25rpx;
	background: #FFF;
	.for{
		display: flex;
		align-items: center;
		padding: 25rpx 0;
		background: #FFF;
		border-bottom: 1px dotted $background;
		._sort{
			color: $placeholder;
		}
		._name{
			padding-left: 5rpx;
		}
		._post-count{
			font-size: 22rpx;
			color: $placeholder;
			padding-left: 10rpx;
		}
		._right{
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			view{
				display: flex;
				align-items: center;
				padding-left: 15rpx;
				line-height: 28rpx;
				text{
					color: $placeholder;
					font-size: 28rpx;
				}
			}
		}
	}
	.for:nth-child(1){
		._sort{
			color: $blue;
		}
	}
	.for:nth-child(2){
		._sort{
			color: $red;
		}
	}
	.for:nth-child(3){
		._sort{
			color: $orange;
		}
	}
	.more-content{
		padding: 25rpx 0;
		font-size: 22rpx;
		line-height: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: $placeholder;
	}
	._loading{
		background: #FFF;
		padding: 25rpx 0 1rpx 0;
		.skeleton-screen{
			width: 100%;
			height: 50rpx;
			margin-bottom: 25rpx;
		}
	}
}
</style>